<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="js/avalon.js"></script>
</head>
<body>
 <button onclick="switchObj()">switch</button>
	<table ms-controller="hello" >
	<tr ms-repeat="Persons">
		<td><input type="checkbox" ms-attr-id="1_{{$index}}"/><label ms-attr-for="1_{{$index}}">{{$index}}</label></td>
		<td>{{el.name}}</td>
		<td>{{el.sex}}</td>
		<td>{{el.birthday | date('yyyy-MM-dd mm:HH:ss')}}</td>
		<td>
			<table>
				<tr ms-repeat-introduce="el.introduce">
					<td><input type="checkbox" ms-attr-id="1_{{$outer.$index}}_{{$index}}"><label ms-attr-for="1_{{$outer.$index}}_{{$index}}">{{$index}}</label></td>
					<td>{{introduce.info}}</td>
					<td><button ms-on-click="$remove">删除</button></td>
				</tr>
			</table>
		</td>
		<td><button ms-on-click="$remove">删除</button></td>
	</tr>
		<!--<div>name:{{el.name}}</div>
		<div>sex:{{el.sex}}</div> 
		<div>birthday:{{el.birthday | date('yyyy-MM-dd mm:HH:ss')}}</div>
	-->
	</table>
	 <script type="avalon" id="tmpl">
            <ul ms-each-el="el.subtree">
            <li>{{el.text}}<div ms-include="'tmpl'" ms-visible="el.subtree.length" ></div></li>
            </ul>
        </script>
        <div ms-controller="tree">
        	<ul ms-each-el="tree">
            	<li>{{el.text}}<div ms-include="'tmpl'" ms-visible="el.subtree.length" ></div></li>
       		</ul>	
        </div>
        
	<script>

	
		var obj = {
			name:"张三",
			sex:"男",
			birthday:new Date("1992/10/15"),
			age:new Date().getFullYear()-new Date("1992/10/15").getFullYear(),
			introduce:[{"info":"info"},{"info":"info"},{"info":"info"},{"info":"info"},{"info":"info"},{"info":"info"}]
		},
		newObj = {
			name:"李四",
			sex:"女",
			birthday:new Date("1992/10/15"),
			age:new Date().getFullYear()-new Date("1992/10/15").getFullYear(),
			introduce:[{"info":"info1"},{"info":"info1"},{"info":"info1"},{"info":"info1"},{"info":"info1"},{"info":"info1"}]
		};
		var modal = avalon.define("hello",function(vm){
			vm.Persons = [];
		});
		for(var i = 0 ; i < 4 ; i++){
			modal.Persons.push(obj);
		}
		function switchObj(){
			var newPersons = [],tobj;
			for(var i = 0 ; i < 4 ; i++){
				newPersons.push(newObj);
			}
			tobj = obj;
			obj = newObj;
			newObj = tobj;
			modal.Persons = newPersons;
		}
		
		Person2 = {
			name:"张三",
			sex:"男",
			birthday:new Date("1992/10/15"),
			age:new Date().getFullYear()-new Date("1992/10/15").getFullYear(),
			introduce:"<div style='text-align:center'><h2>world  is so big...</h2><div>people is so small</div><ul><li>1-option</li><li>2-option</li><li>3-option</li><li>4-option</li><li>5-option</li></ul></div>"
		}
		 avalon.define("tree", function(vm) {
                vm.tree = [
                    {text: "aaa", subtree: [
                            {text: 1111, subtree: []},
                            {text: 2222, subtree: [
                                    {text: 777, subtree: []}
                                ]},
                            {text: 3333, subtree: [
                                    {text: 8888, subtree: []},
                                    {text: 999, subtree: []}
                                ]}
                        ]},
                    {text: "bbb", subtree: [
                            {text: 4444, subtree: []},
                            {text: 5555, subtree: []},
                            {text: 6666, subtree: []}
                        ]},
                    {text: "ccc", subtree: []},
                    {text: "ddd", subtree: []},
                    {text: "eee", subtree: []},
                    {text: "fff", subtree: []}
                ]

            })
	</script>
</body>
</html>